from django.contrib import admin
from . import models
from celery_tasks.static_html.tasks import generate_static_list_search_html, generate_static_sku_detail_html


# Register your models here.

class GoodsCategoryAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        obj.save()
        generate_static_list_search_html.delay()

    def delete_model(self, request, obj):
        obj.delete()
        generate_static_list_search_html.delay()


class SKUModelAdmin(admin.ModelAdmin):
    """当运营点击保存商品详情页的时候生成静态页面"""

    def save_model(self, request, obj, form, change):
        sku_id = obj.id
        obj.save()
        generate_static_sku_detail_html.delay(sku_id)


admin.site.register(models.GoodsCategory, GoodsCategoryAdmin)
admin.site.register(models.GoodsChannel)
admin.site.register(models.Goods)
admin.site.register(models.Brand)
admin.site.register(models.GoodsSpecification)
admin.site.register(models.SpecificationOption)
admin.site.register(models.SKU,SKUModelAdmin)
admin.site.register(models.SKUSpecification)
admin.site.register(models.SKUImage)
